/**
 * @version 2007-1-25
 * @author xalinx at gmail dot com
 */
package org.nanhill.xconv;

import java.io.File;
import java.io.IOException;

import org.nanhill.commons.io.AbstractFileConverter;
import org.nanhill.commons.io.FileKit;

/**
 * @version 2007-1-25
 * @author xalinx at gmail dot com
 * 
 */
public class FileEncodingConverter extends AbstractFileConverter {
	private String fromEncoding;

	private String toEncoding;

	public FileEncodingConverter(String fromEncoding, String toEncoding) {
		this.fromEncoding = fromEncoding;
		this.toEncoding = toEncoding;
	}

	/**
	 * @see org.nanhill.commons.io.AbstractFileVisitor#visitDir(java.io.File)
	 */
	@Override
	protected void convertDir(File fromDir, File toDir) {
		if (!toDir.exists()) {
			toDir.mkdir();
		}
	}

	/**
	 * @throws IOException
	 * @see org.nanhill.commons.io.AbstractFileVisitor#visitFile(java.io.File)
	 */
	@Override
	protected void convertFile(File fromFile, File toFile) throws IOException {
		FileKit.convertFileEncoding(fromEncoding, toEncoding, fromFile, toFile);
	}

}
